<?php 
header("content-type:text/html;charset=utf-8");
include_once("../PHPExcel-1.8/Classes/PHPExcel.php");
$dsn = "mysql:host=127.0.0.1;dbname=goods;charset=utf8";
$pdo = new PDO($dsn,"root","root");
$sql = "select * from imports";
$st = $pdo->query($sql);
$data = $st->fetchAll(PDO::FETCH_ASSOC);
// print_r($data);die;
$objPHPExcel = new PHPExcel();
// print_r($objPHPExcel);die;
$objPHPExcel ->setActiveSheetIndex(0)
		     ->setCellValue('A1', 'uname')
		     ->setCellValue('B1', 'age')
		     ->setCellValue('C1', 'money');
// print_r($theer);die;
$i = 2;
foreach ($data as $k => $v) {
	// print_r($v);die;
    $objPHPExcel ->getActiveSheet()
    			 ->setCellValue('A'.$i, $v['uname'])
			     ->setCellValue('B'.$i, $v['age'])
		         ->setCellValue('C'.$i, $v['money']);
    $i++;
}
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="01simple.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
 ?>